package com.microservice.api.system.fallbackFactory;

import com.microservice.api.system.RemoteSystemService;
import com.microservice.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RemoteSystemFallbackFactory implements FallbackFactory<RemoteSystemService> {

    @Override
    public RemoteSystemService create(Throwable cause) {
        return new RemoteSystemService() {

            @Override
            public AjaxResult getUserByUsername(String username) {
                log.error("根据用户名称获取用户信息失败:{}", cause.getMessage(),cause);
                return AjaxResult.error(500, "根据用户名称获取用户信息失败");
            }

            @Override
            public AjaxResult getPermissionByUsername(String username) {
                log.error("根据用户名称获取用户权限失败:{}", cause.getMessage(),cause);
                return AjaxResult.error(500, "根据用户名称获取用户权限失败");
            }

            @Override
            public AjaxResult getRoleByUsername(String username) {
                log.error("根据用户名称获取用户角色失败:{}", cause.getMessage(),cause);
                return AjaxResult.error(500, "根据用户名称获取用户角色失败");
            }

            @Override
            public AjaxResult getUserList() {
                log.error("获取用户列表失败:{}", cause.getMessage(),cause);
                return AjaxResult.error(500, "获取用户列表失败");
            }
        };
    }
}
